package com.exartisan.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.exartisan.bean.Event;
import com.exartisan.thanhdoanhn.R;
import com.loopj.android.image.SmartImageView;

public class EventListAdapter extends BaseAdapter {
	
	private LayoutInflater inflater;
	private ArrayList<Event> events;
	
	public EventListAdapter() {
		
	}
	
	public EventListAdapter(Context ctx, ArrayList<Event> events) {
		this.inflater = LayoutInflater.from(ctx);
		this.events = events;
	}

	@Override
	public int getCount() {
		return events.size();
	}

	@Override
	public Object getItem(int position) {
		return events.get(position);
	}

	@Override
	public long getItemId(int position) {
		return events.get(position).getEventID();
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView==null) {
			holder = new ViewHolder();
			convertView = inflater.inflate(R.layout.row, parent, false);
			holder.imgCover = (SmartImageView) convertView.findViewById(R.id.imgCover);
			holder.tvName = (TextView) convertView.findViewById(R.id.tvName);
			holder.tvDesc = (TextView) convertView.findViewById(R.id.tvDesc);
			convertView.setTag(holder);
		} else holder = (ViewHolder) convertView.getTag();
		
		holder.imgCover.setImageUrl(events.get(position).getThumbUrl());
		holder.tvDesc.setText(events.get(position).getDescription());
		holder.tvName.setText(events.get(position).getEventName());
		
		return convertView;
	}
	
	private class ViewHolder{
		SmartImageView imgCover;
		TextView tvName;
		TextView tvDesc;
	}

}
